/*
Kakine
ActionScript Framework
Copyright © 2011, PUNY, LLC.

This file is part of KAKINE.

KAKINE is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

KAKINE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with KAKINE.  If not, see <http://www.gnu.org/licenses/>.
*/ 
package com.puny.utils
{
	public class ColorGenerator extends Object
	{
		private const RED:uint = 0x10000;
		private const GREEN:uint = 0x100;
		private const BLUE:uint = 0x1;
		private var _red:*;
		private var _green:*;
		private var _blue:*;
		/**
		 * Constructor
		 * @param red a value or two values for red
		 * @param green a value or two values for green
		 * @param blue a value or two values for blue
		 * 
		 * @example
		 * <listing>
		 * var generator:ColorGenerator = new ColorGenerator([0xAA,0xCC],0,0);
		 * var color:uint = generator.getColor // color should be between 0xAA0000 and 0xCC0000.
		 * </listing>
		 */
		public function ColorGenerator(red:*,green:*,blue:*) {
			_red = red;
			_green = green;
			_blue = blue;
		}
		
		/**
		 * color value
		 * @return 
		 * 
		 */
		public function getColor():uint {
			return unit(_red)*RED + unit(_green)*GREEN + unit(_blue)*BLUE;
		}
		
		private function unit(u:*):uint {
			try {
				if (u is Array) {
					return uint(Random.between(u[0],u[1]));
				} else {
					return u;
				}
			} catch(e:Error) {
				throw e;
			}
			return 0;
		}
	}
}